const HtmlWebpackPlugin = require("html-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
      module.exports       = {
  module: {
    rules: [
      {
        test   : /\.(js|jsx)$/,
        exclude: /node_modules/,
        use    : {
          loader: "babel-loader"
        }
      },
      {
        test: /\.html$/,
        use : [
          {
            loader : "html-loader",
            options: {
              minimize: true
            }
          }
        ]
      },
      {
        test: /\.css$/,
        use : [MiniCssExtractPlugin.loader, "css-loader"]
      },
      {
        test: /\.scss$/,
        use : [MiniCssExtractPlugin.loader, "css-loader", "sass-loader"]
      }
    ]
  },
  plugins: [
    new HtmlWebpackPlugin({
      // Also generate a test.html
      filename: "./index.html",
      template: "./src/index.html"
    }),
    new MiniCssExtractPlugin({
      filename     : "[name].css",
      chunkFilename: "[id].css"
    })
  ],
  optimization: {
    splitChunks: {
      chunks                : "async",
      minSize               : 30000,
      maxSize               : 2048000,
      minChunks             : 1,
      maxAsyncRequests      : 5,
      maxInitialRequests    : 3,
      automaticNameDelimiter: "~",
      name                  : true,
      cacheGroups           : {
        vendors: {
          test    : /[\\/]node_modules[\\/]/,
          priority: -10
        },
        default: {
          minChunks         : 2,
          priority          : -20,
          reuseExistingChunk: true
        }
      }
    }
  }
};
